<%+cbi/valueheader%>
<input type="button" class="btn cbi-button cbi-button-apply" id="apply_update_button" value="<%:Clear Log%>" onclick="apply_del_log()"/>
<input type="checkbox" name="NAME" value="reverse" onclick="reverselog()" style="vertical-align:middle;height:auto;"><%:Reverse%></input>
<textarea id="cbid.logview.1.conf" class="cbi-input-textarea" style="width: 100%;display:inline" data-update="change" rows="32" cols="60" readonly="readonly" > </textarea>

<script type="text/javascript">//<![CDATA[
var islogreverse=false;

function createAndDownloadFile(fileName,content){
	var aTag=document.createElement('a');
	var blob=new Blob([content]);
	aTag.download=fileName;
	aTag.href=URL.createObjectURL(blob);
	aTag.click();
	URL.revokeObjectURL(blob);
}

function apply_del_log(){
	XHR.get('<%=url([[admin]],[[control]],[[taskplan]],[[dellog]])%>',null,function(x,data){
	var lv=document.getElementById('cbid.logview.1.conf');
		lv.innerHTML="";
	}
		);
	return
}

function reverselog(){
	var lv=document.getElementById('cbid.logview.1.conf');
	lv.innerHTML=lv.innerHTML.split('\n').reverse().join('\n')
	if (islogreverse){
	islogreverse=false;
	}else{
	islogreverse=true;
	}
	return
}

XHR.poll(3,'<%=url([[admin]],[[control]],[[taskplan]],[[getlog]])%>',null,
	function(x,data){
		var lv=document.getElementById('cbid.logview.1.conf');
		lv.innerHTML=""
		if (x.responseText && lv){
			if (islogreverse){
				lv.innerHTML=x.responseText.split('\n').reverse().join('\n')+lv.innerHTML;
			}else{
				lv.innerHTML+=x.responseText;
			}
		}
	}
)

//]]>
</script>
<%+cbi/valuefooter%>